import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state: () => ({
    userInfo: {
      userId: "",
      userName: "",
      token: "",
    },
  }),
  actions: {
    /*
     * 登录并设置用户信息
     */
    setStore() {
      this.userInfo.token = "";
      this.userInfo.userId = "";
      this.userInfo.userName = "";
      uni.setStorageSync("userInfo", this.userInfo);
    },

    /*
     * 退出登录并清除用户信息
     */
    logOut() {
      return new Promise((resolve, reject) => {
        this.userInfo.token = "";
        this.userInfo.userId = "";
        this.userInfo.userName = "";
        uni.removeStorageSync("userInfo");
        resolve();
      });
    },
  },
});
